<template >
  <div>
    <section class="jumbotron">
      <h3 class="jumbotron-heading">Search Github Users</h3>
      <div>
        <input
          type="text"
          placeholder="enter the name you search"
          v-model="keyword"
        />&nbsp;
        <button @click="sendUser">Search</button>
      </div>
    </section>
  </div>
</template>
<script>
import axios from "axios";
export default {
  name: "Search",
  data() {
    return {
      keyword: "",
    };
  },
  methods: {
    sendUser() {
      this.$bus.$emit("updateUsers", {
        isFirst: false,
        isLoading: true,
        errMsg: "",
        users: [],
      });
      axios.get(`https://api.github.com/search/users?q=${this.keywords}`).then(
        (res) => {
          console.log("请求成功", res.data);
          this.$bus.$emit("updateUsers", {
            isLoading: false,
            errMsg: "",
            users: res.data.items,
          });
        },
        (err) => {
          this.$bus.$emit("updateUsers", {
            isLoading: false,
            errMsg: "err.message",
            users: [],
          });
        }
      );
    },
  },
};
</script>
<style  scoped>
</style>